﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Slaks.Graphs.ShenkerGraph;

namespace UI
{
    public partial class GraphUI : Form
    {
        public GraphUI()
        {
            InitializeComponent();
        }

        List<ExperimentItem> items = new List<ExperimentItem> ();
        List<ExperimentDesign> experiments = new List<ExperimentDesign>();

        private void btn_AddExperiment_Click(object sender, EventArgs e)
        {
            ExperimentDesign ED = new ExperimentDesign();
            experiments.Add(ED);
            if (ED.ShowDialog() == DialogResult.OK)
            {
                items.Add(ED.Itm);
                listBox1.Items.Clear();
                for (int i = 0; i < items.Count; i++)
                    listBox1.Items.Add(items[i].toDisplayFields());
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void btn_RemoveExperiment_Click(object sender, EventArgs e)
        {
            items.RemoveAt(listBox1.SelectedIndex);
            listBox1.Items.Clear();
            for (int i = 0; i < items.Count; i++)
                listBox1.Items.Add(items[i].toDisplayFields());
        }

        private void button1_Click(object sender, EventArgs e)
        {
            /*List<ExperimentItem> clone = new List<ExperimentItem>();
            for ( int i = 0; i < items.Count; i++ )
            {
                ExperimentItem ei = items[i];
                ExperimentItem newEI;
                if (ei is CategorizationExperiment)
                    newEI = new CategorizationExperiment(ei.Fields, CategorizationFactory.Instance.GetInstance(ei.AlgorithmName), ei.AlgorithmName);
                else
                    newEI = new ClusteringExperiment(ei.Fields, ClusteringFactory.Instance.GetInstance(ei.AlgorithmName), ei.AlgorithmName);
                clone.Add(newEI);
            }
            RunningPleaseWait frm = new RunningPleaseWait(clone);
            frm.ShowDialog();*/
            for ( int i = 0; i < items.Count; i++ )
                items [ i ].runExperiment();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            if (listBox1.SelectedIndex < 0 && listBox1.Items.Count > 0)
            {
                listBox1.SelectedIndex =  0;
            }
            ExperimentDesign ed = experiments[listBox1.SelectedIndex];
            if (ed.ShowDialog() == DialogResult.OK)
            {
                items [ listBox1.SelectedIndex ] = ed.Itm;
                listBox1.Items.Clear();
                for (int i = 0; i < items.Count; i++)
                    listBox1.Items.Add(items[i].toDisplayFields());
            }
        }
    }
}
